//
//  UIView+ModalAnimation.m
//  UIControls
//
//  Created by 21CN Vgo on 12-7-13.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "UIView+ModalAnimation.h"


@interface UIViewDelegate : NSObject  
{  
	CFRunLoopRef currentLoop;  
}  
@end  

@implementation UIViewDelegate  
-(id) initWithRunLoop: (CFRunLoopRef)runLoop   
{  
	if (self = [super init]) currentLoop = runLoop;  
	return self;  
}  

-(void) animationFinished: (id) sender  
{  
	CFRunLoopStop(currentLoop);  
}  
@end

@implementation UIView (ModalAnimationHelper)

+ (void) commitModalAnimations
{  
	CFRunLoopRef currentLoop = CFRunLoopGetCurrent();  
	
	UIViewDelegate *uivdelegate = [[UIViewDelegate alloc] initWithRunLoop:currentLoop];  
	[UIView setAnimationDelegate:uivdelegate];  
	[UIView setAnimationDidStopSelector:@selector(animationFinished:)];  
	[UIView commitAnimations];  
	CFRunLoopRun();  
	[uivdelegate release];  
}

@end 
